fix: make func pack gracefully handle missing local.settings.json (issue #4783)#4829
fix: make func pack gracefully handle missing local.settings.json (issue #4783)#4829MO2k4 wants to merge 9 commits intoAzure:mainfrom
Conversation
|
@MO2k4 - thanks for the contribution. I do have concerns about this approach. I think for now it might be better to drop the runtime inference logic ( Reliably detecting the worker runtime from project files is not easily feasible for Azure Functions. In my opinion, silent misdetection is worse than a clear error. If we guess wrong, the user gets a confusing failure much later in the pack/deploy pipeline — harder to diagnose than being told upfront what to do. Missing runtimes entirelyJava and Custom handler projects are not covered Incomplete coverage of existing runtimesf# projects are not covered Fragile heuristics
Priority / ordering problems
The
|
|
@liliankasem thanks for the feedback Dropped InferWorkerRuntimeFromProjectFiles entirely. RunAsync now throws directly when the runtime can't be determined:
Also removed PackActionInferRuntimeTests.cs. The remaining PackActionRuntimeDetectionTests covers the error path and the env-var bypass case. |
liliankasem
left a comment
There was a problem hiding this comment.
Have you tested this by build the CLI locally and running it? Can you share screenshots of what these error messages look like and what use cases you have tested?
|
Local builds are not possible in this environment — the repo's What I can show is the exact error message produced by the code path (from And for the The unit tests in
|
Adds PackAction.InferWorkerRuntimeFromProjectFiles() to detect worker runtime from .csproj, requirements.txt, package.json, profile.ps1, and build-output signals when local.settings.json is absent. Fixes Azure#4783
When FUNCTIONS_WORKER_RUNTIME is not set and local.settings.json is absent (the default CI/CD state), func pack now warns and falls back to project-file inference instead of throwing "Unsupported runtime: None". If inference also fails, a clear CliException with actionable guidance is thrown. Removes the flawed NoBuild-only .dll fallback. Fixes Azure#4783
Per reviewer feedback, project-file inference is fragile and unreliable: - fragile heuristics (Central Package Management breaks .csproj detection) - recursive .dll scan is slow and produces false positives in Python/Node - source files absent in --no-build/CI output dirs anyway Replace with a clear, actionable error directing users to set FUNCTIONS_WORKER_RUNTIME in local.settings.json or as an env var. Remove InferWorkerRuntimeFromProjectFiles and its test suite.
Per reviewer feedback: removing the '&& NoBuild' guard was a regression for users relying on the .dll-based runtime detection in CI/CD pipelines. Restore the fallback but scope it properly: - Only active when --no-build is passed - Searches top-level only (SearchOption.TopDirectoryOnly) to avoid false positives from .dll files in node_modules/, Python venvs, etc. - Emits a deprecation warning directing users to set FUNCTIONS_WORKER_RUNTIME - Falls through to the actionable CliException if no .dll files found Also adds two new unit tests covering the NoBuild + dll and NoBuild + no-dll detection paths.
104d683 to
5695c8c
Compare
You should still be able to test locally. The private feed shouldn't stop you from that; I was able to publish the CLI locally on my personal machine without being logged into my corp account. Please build and test the CLI and provide screenshots. |
|
Just a quick note on process: AI assistance is fine for the code, but I'd appreciate it if review discussions and feedback responses came from you directly. If AI is handling that side of the conversation too, there's no meaningful difference between your contribution and me assigning the issue to Copilot. Part of what makes open source collaboration valuable is the human exchange, and I'd like your engagement here to genuinely be yours. I'll help get this merged, but please keep this in mind for future contributions. |
|
@liliankasem Ok got it. Could you elaborate how to get this running locally without running a dotnet restore? I've tried to build, pack and publish but i receive the following error
|
|
@liliankasem here you can find the testing validation
I've executed the following test cases:
Is there any testcase missing? |
Great, thanks! I think the only one I can think of is validating that local.settings.json with FUNCTIONS_WORKER_RUNTIME still works as expected then lgtm |
|
@liliankasem I added another testcase and here is the validation screenshot, i've created a minimal http func to validate it
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| Environment.SetEnvironmentVariable(Constants.FunctionsWorkerRuntime, null); | ||
| } | ||
|
|
||
| public void Dispose() |
There was a problem hiding this comment.
Can you fix this
public void Dispose()
{
try
{
Directory.Delete(_tempDir, recursive: true);
}
catch (IOException)
{
// Best-effort cleanup; files may still be locked by the test host.
}
}
Alternatively, ensure all IDisposable resources are fully disposed before Dispose() runs.
There was a problem hiding this comment.
I've checked and there should no disposable objects currently in the test. Code wise it is adjusted with the reset mechanism for the current environment variable usage
|
@liliankasem I got some push back on another pr for using Environment and checked this here too, should i adjust this here as well since this was already pre existing or do this properly in a new pr? |











Summary
Fixes #4783
When
func packis run whereFUNCTIONS_WORKER_RUNTIMEis not set (e.g. a CI/CD pipeline wherelocal.settings.jsonis gitignored), the command throws"Unsupported runtime: None"with no actionable guidance.This PR improves the error handling in
PackAction.RunAsync():--no-buildmode: preserves the existing.dll-based fallback, but scoped to top-level files only (SearchOption.TopDirectoryOnly) to avoid false positives fromnode_modules/, Python venvs, etc. Emits a deprecation warning directing users to setFUNCTIONS_WORKER_RUNTIMEexplicitly.CliExceptionwith explicit guidance if the runtime cannot be determined.Runtime detection order
FUNCTIONS_WORKER_RUNTIMEenvironment variable (unchanged)local.settings.jsonviaSecretsManager(unchanged)--no-buildonly: top-level.dllfallback with deprecation warning (scoped from previousAllDirectoriestoTopDirectoryOnly)CliExceptionwith message:Files changed
src/Cli/func/Actions/LocalActions/PackAction/PackAction.cs.dllfallback to top-level + add deprecation warning; addCliExceptionfor unresolvable runtimetest/Cli/Func.UnitTests/ActionsTests/PackAction/PackActionRuntimeDetectionTests.cs--no-build+ dlls → no error,--no-build+ no dlls → errorTest plan
PackActionRuntimeDetectionTests— 4 tests covering all detection pathsRelease notes
func packnow emits a clear, actionable error whenFUNCTIONS_WORKER_RUNTIMEcannot be determined, instead of the crypticUnsupported runtime: None. The existing.dll-based fallback for--no-buildis preserved but scoped to top-level files only, with a deprecation warning.